*********************************************************************
*** Political costs of trade war tariffs 
*** Edward D. Mansfield & Omer Solodoch 
*** Replication code for analysis of the 2018 CCES  
*** Note: replicators must install the following packages from the SSC Archive:
*** ssc install ebalance
*** ssc install outtable
*** ssc install coefplot
*** ssc install esttab
*** ssc install scheme_rbn1mono
*********************************************************************
clear all
version 17
*** Set working directory
capture cd "XXXX"
*** Load dataset
use "MSJOP_CCES.dta", clear
*********************************************************************


************************************
areg HouseVote_Rep Trump_approve_d  trade_pol_china2   Zemp_chn_target_cum_sept county_repshare_house1416 swing_dist_20_1416 i.PID3  i.educ faminc_decile   i.employ  age i.gender i.race_ethnicity i.urbancity [aw=commonpostweight] if commonpostweight <., absorb(state) cl(cty_fips)
gen sample_est=e(sample)

************************************************************
*** Table A-18: sample: Trump voters (2016)
************************************************************
estimates clear
eststo: areg Trump_approve_d   trade_pol_china2   Zemp_chn_target_cum_sept county_repshare_house1416 swing_dist_20_1416   i.PID3  i.educ faminc_decile   i.employ  age i.gender i.race_ethnicity i.urbancity i.industryclass [aw=commonweight] if sample_est==1 & VT2016_1==1, absorb(state) cl(cty_fips)
estadd local controls "\checkmark", replace
estadd local sfixedef "\checkmark", replace
estadd local cfixedef "", replace
eststo: areg Trump_approve_d   trade_pol_china2   Zemp_chn_target_cum_sept county_repshare_house1416 swing_dist_20_1416  i.PID3  i.educ faminc_decile   i.employ  age i.gender i.race_ethnicity i.urbancity i.industryclass [aw=commonweight] if sample_est==1 & VT2016_1==1, absorb(cty_fips) cl(cty_fips)
estadd local controls "\checkmark", replace
estadd local sfixedef "", replace
estadd local cfixedef "\checkmark", replace

eststo: areg HouseVote_Rep   trade_pol_china2   Zemp_chn_target_cum_sept county_repshare_house1416 swing_dist_20_1416   i.PID3  i.educ faminc_decile   i.employ  age i.gender i.race_ethnicity i.urbancity i.industryclass [aw=commonpostweight] if sample_est==1 & VT2016_1==1, absorb(state) cl(cty_fips)
estadd local controls "\checkmark", replace
estadd local sfixedef "\checkmark", replace
estadd local cfixedef "", replace
eststo: areg HouseVote_Rep   trade_pol_china2   Zemp_chn_target_cum_sept county_repshare_house1416 swing_dist_20_1416   i.PID3  i.educ faminc_decile   i.employ  age i.gender i.race_ethnicity i.urbancity i.industryclass [aw=commonpostweight] if sample_est==1 & VT2016_1==1, absorb(cty_fips) cl(cty_fips)
estadd local controls "\checkmark", replace
estadd local sfixedef "", replace
estadd local cfixedef "\checkmark", replace

eststo: areg HouseVote_novote   trade_pol_china2   Zemp_chn_target_cum_sept county_repshare_house1416 swing_dist_20_1416   i.PID3  i.educ faminc_decile   i.employ  age i.gender i.race_ethnicity i.urbancity i.industryclass [aw=commonpostweight] if VT2016_1==1, absorb(state) cl(cty_fips)
estadd local controls "\checkmark", replace
estadd local sfixedef "\checkmark", replace
estadd local cfixedef "", replace
eststo: areg HouseVote_novote   trade_pol_china2   Zemp_chn_target_cum_sept county_repshare_house1416 swing_dist_20_1416   i.PID3  i.educ faminc_decile   i.employ  age i.gender i.race_ethnicity i.urbancity i.industryclass [aw=commonpostweight] if VT2016_1==1, absorb(cty_fips) cl(cty_fips)
estadd local controls "\checkmark", replace
estadd local sfixedef "", replace
estadd local cfixedef "\checkmark", replace

 esttab est1 est2 est3 est4 est5 est6, keep(trade_pol_china2 Zemp_chn_target_cum_sept) ///
order(trade_pol_china2 Zemp_chn_target_cum_sept) ///
 se(3) b(3) replace star(+ 0.10 * 0.05 ** 0.01) label  nonotes nogaps  ///
 nodepvars mtitles("Trump Approval" "" "Voted GOP" "" "Didn't vote" "") ///
 s(controls sfixedef cfixedef N r2, fmt(0 0 0 0 3) label("Covariates" "State FE" "County FE" "Observations" "R-squared"))

************************************************************
*** Table A-19: full sample
************************************************************
estimates clear
eststo: areg Trump_approve_d   trade_pol_china2   Zemp_chn_target_cum_sept county_repshare_house1416 swing_dist_20_1416   i.PID3  i.educ faminc_decile   i.employ  age i.gender i.race_ethnicity i.urbancity i.industryclass [aw=commonweight] if sample_est==1, absorb(state) cl(cty_fips)
estadd local controls "\checkmark", replace
estadd local sfixedef "\checkmark", replace
estadd local cfixedef "", replace
eststo: areg Trump_approve_d   trade_pol_china2  Zemp_chn_target_cum_sept county_repshare_house1416 swing_dist_20_1416   i.PID3  i.educ faminc_decile   i.employ  age i.gender i.race_ethnicity i.urbancity i.industryclass [aw=commonweight] if sample_est==1, absorb(cty_fips) cl(cty_fips)
estadd local controls "\checkmark", replace
estadd local sfixedef "", replace
estadd local cfixedef "\checkmark", replace

eststo: areg HouseVote_Rep   trade_pol_china2   Zemp_chn_target_cum_sept county_repshare_house1416 swing_dist_20_1416 i.PID3  i.educ faminc_decile   i.employ  age i.gender i.race_ethnicity i.urbancity i.industryclass [aw=commonpostweight] if sample_est==1, absorb(state) cl(cty_fips)
estadd local controls "\checkmark", replace
estadd local sfixedef "\checkmark", replace
estadd local cfixedef "", replace
eststo: areg HouseVote_Rep   trade_pol_china2   Zemp_chn_target_cum_sept county_repshare_house1416 swing_dist_20_1416   i.PID3  i.educ faminc_decile   i.employ  age i.gender i.race_ethnicity i.urbancity i.industryclass [aw=commonpostweight] if sample_est==1, absorb(cty_fips) cl(cty_fips)
estadd local controls "\checkmark", replace
estadd local sfixedef "", replace
estadd local cfixedef "\checkmark", replace

eststo: areg HouseVote_novote   trade_pol_china2   Zemp_chn_target_cum_sept county_repshare_house1416 swing_dist_20_1416   i.PID3  i.educ faminc_decile   i.employ  age i.gender i.race_ethnicity i.urbancity i.industryclass [aw=commonpostweight], absorb(state) cl(cty_fips)
estadd local controls "\checkmark", replace
estadd local sfixedef "\checkmark", replace
estadd local cfixedef "", replace
eststo: areg HouseVote_novote   trade_pol_china2   Zemp_chn_target_cum_sept county_repshare_house1416 swing_dist_20_1416   i.PID3  i.educ faminc_decile   i.employ  age i.gender i.race_ethnicity i.urbancity i.industryclass [aw=commonpostweight], absorb(cty_fips) cl(cty_fips)
estadd local controls "\checkmark", replace
estadd local sfixedef "", replace
estadd local cfixedef "\checkmark", replace

 esttab est1 est2 est3 est4 est5 est6, keep(trade_pol_china2 Zemp_chn_target_cum_sept) ///
order(trade_pol_china2 Zemp_chn_target_cum_sept) ///
 se(3) b(3) replace star(+ 0.10 * 0.05 ** 0.01) label  nonotes nogaps  ///
 nodepvars mtitles("Trump Approval" "Trump Approval" "Voted GOP" "Voted GOP" "Didn't vote" "Didn't vote") ///
 s(controls sfixedef cfixedef N r2, fmt(0 0 0 0 3) label("Covariates" "State FE" "County FE" "Observations" "R-squared"))


************************************************************
*** Table A-20 Senate vote, Trump voters
************************************************************
estimates clear
eststo: areg SenVote_Rep   trade_pol_china2   Zemp_chn_target_cum_sept county_repshare_house1416 swing_dist_20_1416   i.PID3  i.educ faminc_decile   i.employ  age i.gender i.race_ethnicity i.urbancity i.industryclass [aw=commonpostweight] if sample_est==1 & VT2016_1==1, absorb(state) cl(cty_fips)
estadd local controls "\checkmark", replace
estadd local sfixedef "\checkmark", replace
estadd local cfixedef "", replace
eststo: areg SenVote_Rep   trade_pol_china2   Zemp_chn_target_cum_sept county_repshare_house1416 swing_dist_20_1416   i.PID3  i.educ faminc_decile   i.employ  age i.gender i.race_ethnicity i.urbancity i.industryclass [aw=commonpostweight] if sample_est==1 & VT2016_1==1, absorb(cty_fips) cl(cty_fips)
estadd local controls "\checkmark", replace
estadd local sfixedef "", replace
estadd local cfixedef "\checkmark", replace
eststo: areg SenVote_novote   trade_pol_china2   Zemp_chn_target_cum_sept county_repshare_house1416 swing_dist_20_1416   i.PID3  i.educ faminc_decile   i.employ  age i.gender i.race_ethnicity i.urbancity i.industryclass [aw=commonpostweight] if VT2016_1==1, absorb(state) cl(cty_fips)
estadd local controls "\checkmark", replace
estadd local sfixedef "\checkmark", replace
estadd local cfixedef "", replace
eststo: areg SenVote_novote   trade_pol_china2   Zemp_chn_target_cum_sept county_repshare_house1416 swing_dist_20_1416   i.PID3  i.educ faminc_decile   i.employ  age i.gender i.race_ethnicity i.urbancity i.industryclass [aw=commonpostweight] if VT2016_1==1, absorb(cty_fips) cl(cty_fips)
estadd local controls "\checkmark", replace
estadd local sfixedef "", replace
estadd local cfixedef "\checkmark", replace
*** Table A-20 Senate vote, Trump voters
 esttab est1 est2 est3 est4, keep(trade_pol_china2 Zemp_chn_target_cum_sept) ///
order(trade_pol_china2 Zemp_chn_target_cum_sept) ///
 se(3) b(3) replace star(+ 0.10 * 0.05 ** 0.01) label  nonotes nogaps  ///
 nodepvars mtitles("Voted GOP" "" "Didn't vote" "") ///
 s(controls sfixedef cfixedef N r2, fmt(0 0 0 0 3) label("Covariates" "State FE" "County FE" "Observations" "R-squared"))

 
************************************************************
*** Table A-21: control for Trump approval
************************************************************
estimates clear
eststo: areg HouseVote_Rep   trade_pol_china2   Zemp_chn_target_cum_sept county_repshare_house1416 swing_dist_20_1416   i.PID3  i.educ faminc_decile   i.employ  age i.gender i.race_ethnicity i.urbancity i.industryclass [aw=commonpostweight] if sample_est==1 & VT2016_1==1, absorb(inputstate) cl(cty_fips)
estadd local controls "\checkmark", replace
estadd local sfixedef "\checkmark", replace

eststo: areg HouseVote_Rep   trade_pol_china2 Trump_approve_d   Zemp_chn_target_cum_sept county_repshare_house1416 swing_dist_20_1416   i.PID3  i.educ faminc_decile   i.employ  age i.gender i.race_ethnicity i.urbancity i.industryclass [aw=commonpostweight] if sample_est==1 & VT2016_1==1, absorb(inputstate) cl(cty_fips)
estadd local controls "\checkmark", replace
estadd local sfixedef "\checkmark", replace

 esttab est1 est2, keep(trade_pol_china2 Zemp_chn_target_cum_sept Trump_approve_d) ///
order(trade_pol_china2 Zemp_chn_target_cum_sept Trump_approve_d) ///
 se(3) b(3) replace star(+ 0.10 * 0.05 ** 0.01) label  nonotes nogaps  ///
 nodepvars mtitles("" "") ///
 s(controls sfixedef N r2, fmt(0 0 0 3) label("Covariates" "State FE" "Observations" "R-squared"))

************************************************************
*** Table A-22: control for Rs and Trump's perceived ideology
************************************************************
estimates clear
eststo: areg HouseVote_Rep   trade_pol_china2 Zemp_chn_target_cum_sept county_repshare_house1416 swing_dist_20_1416   i.PID3  i.educ faminc_decile   i.employ  age i.gender i.race_ethnicity i.urbancity i.industryclass [aw=commonpostweight] if sample_est==1 & VT2016_1==1 & Trump_cons_gap<., absorb(state) cl(cty_fips)
estadd local controls "\checkmark", replace
estadd local sfixedef "\checkmark", replace

eststo: areg HouseVote_Rep   trade_pol_china2  R_ideol Zemp_chn_target_cum_sept county_repshare_house1416 swing_dist_20_1416   i.PID3  i.educ faminc_decile   i.employ  age i.gender i.race_ethnicity i.urbancity i.industryclass [aw=commonpostweight] if sample_est==1 & VT2016_1==1 & Trump_cons_gap<., absorb(state) cl(cty_fips)
estadd local controls "\checkmark", replace
estadd local sfixedef "\checkmark", replace

eststo: areg HouseVote_Rep   trade_pol_china2  R_ideol Trump_ideol Zemp_chn_target_cum_sept county_repshare_house1416 swing_dist_20_1416   i.PID3  i.educ faminc_decile   i.employ  age i.gender i.race_ethnicity i.urbancity i.industryclass [aw=commonpostweight] if sample_est==1 & VT2016_1==1 & Trump_cons_gap<., absorb(state) cl(cty_fips)
estadd local controls "\checkmark", replace
estadd local sfixedef "\checkmark", replace

eststo: areg HouseVote_Rep   trade_pol_china2 Trump_cons_gap  Zemp_chn_target_cum_sept county_repshare_house1416 swing_dist_20_1416   i.PID3  i.educ faminc_decile   i.employ  age i.gender i.race_ethnicity i.urbancity i.industryclass [aw=commonpostweight] if sample_est==1 & VT2016_1==1 & Trump_cons_gap<., absorb(state) cl(cty_fips)
estadd local controls "\checkmark", replace
estadd local sfixedef "\checkmark", replace

*export table
 esttab est1 est2 est3 est4, keep(trade_pol_china2 Zemp_chn_target_cum_sept R_ideol Trump_ideol Trump_cons_gap) ///
order(trade_pol_china2 Zemp_chn_target_cum_sept R_ideol Trump_ideol Trump_cons_gap) ///
 se(3) b(3) replace star(+ 0.10 * 0.05 ** 0.01) label  nonotes nogaps  ///
 nodepvars mtitles("" "" "" "") ///
 s(controls sfixedef N r2, fmt(0 0 0 3) label("Covariates" "State FE" "Observations" "R-squared"))
********************************************************
 
******************************** compare to immigration attitudes:
***Principle Component Analysis PCA 
************************************************************
*** Table A-23: PCA: For each summary measure, the values of 
*** first three components are taken from the column "Proportion"  
************************************************************

pca trade_pol_china2 trade_pol_steel_excCMXEU2 withdrawTPP2
predict  protrade_comp1

pca protax_corporate protax_LIhouseholds protax_HIhouseholds
predict protax_comp1

pca guncontrol_permit guncontrol_checks guncontrol_ban
predict guncontrol_comp1

pca proMedicare1 proMedicare2 proMedicare3 proMedicare4
predict proMedicare_comp1

pca proimmig_wall proimmig_DACA proimmig_fam proimmig_sanctuary proimmig_prison
predict proimmig_comp1

pca proChoice1 proChoice2 proChoice3 proChoice4 proChoice5 proChoice6
predict proChoice_comp1

****************************************************************
*pca guncontrol_permit guncontrol_checks guncontrol_ban, mineigen(1)

lab var protrade_comp1 "{bf: Pro-trade component}"
lab var proimmig_comp1 "Pro-immigration component"
lab var protax_comp1 "Pro-tax component"
lab var proMedicare_comp1 "Pro-Medicare component"
lab var guncontrol_comp1 "Anti-guns component"
lab var proChoice_comp1 "Pro-choice component"

****************************************************************
***Principle Component Analysis
****************************************************************

************************************************************
*** Figure A-6: PCA immigration
************************************************************
set scheme rbn3mono
areg HouseVote_Rep   trade_pol_china2  proimmig_wall proimmig_DACA proimmig_fam proimmig_sanctuary proimmig_prison  i.immstat Zemp_chn_target_cum_sept county_repshare_house1416 swing_dist_20_1416   i.PID3  i.educ faminc_decile   i.employ  age i.gender i.race_ethnicity i.urbancity i.industryclass [aw=commonpostweight] if sample_est==1 & VT2016_1==1, absorb(inputstate) cl(cty_fips)

coefplot, drop(_cons) xline(0, lp(dash) lc(gs8)) label keep(trade_pol_china2  proimmig_wall proimmig_DACA proimmig_fam proimmig_sanctuary proimmig_prison) ///
order(proimmig_wall proimmig_sanctuary trade_pol_china2 proimmig_prison proimmig_fam proimmig_DACA) ///
xline(-0.2(0.05)0.1, lwidth(thin) lcolor(gs8%30))  xlabel(-0.2(0.05)0.1, angle(horizontal)) xti(Effect on Pr(vote GOP)) ///
mcolor(maroon) msize(large) ciopts(color(maroon) lwidth(0.7)) 

************************************************************
*** Figure A-7: PCA various issue-areas
************************************************************

foreach var in trade_pol_china2 proimmig_comp1 proChoice_comp1 protax_comp1 proMedicare_comp1 guncontrol_comp1 protrade_comp1 {
	egen `var'Z = std(`var')
}

lab var trade_pol_china2Z "{bf: Oppose: tariffs against China (std)}"
lab var protrade_comp1Z "{bf: Pro-trade component}"
lab var proimmig_comp1Z "Pro-immigration component"
lab var protax_comp1Z "Pro-tax component"
lab var proMedicare_comp1Z "Pro-Medicare component"
lab var guncontrol_comp1Z "Anti-guns component"
lab var proChoice_comp1Z "Pro-choice component"

areg HouseVote_Rep protrade_comp1Z proimmig_comp1Z proChoice_comp1Z protax_comp1Z proMedicare_comp1Z guncontrol_comp1Z  Zemp_chn_target_cum_sept county_repshare_house1416 swing_dist_20_1416   i.PID3  i.educ faminc_decile   i.employ  age i.gender i.race_ethnicity i.urbancity i.industryclass [aw=commonpostweight] if sample_est==1 & VT2016_1==1, absorb(inputstate) cl(cty_fips)
est store pcamodel1Z

areg HouseVote_Rep trade_pol_china2Z proimmig_comp1Z proChoice_comp1Z protax_comp1Z proMedicare_comp1Z guncontrol_comp1Z  Zemp_chn_target_cum_sept county_repshare_house1416 swing_dist_20_1416   i.PID3  i.educ faminc_decile   i.employ  age i.gender i.race_ethnicity i.urbancity i.industryclass [aw=commonpostweight] if sample_est==1 & VT2016_1==1, absorb(inputstate) cl(cty_fips)
est store pcamodel2Z

coefplot pcamodel2Z, bylabel(Model 1) || pcamodel1Z, bylabel(Model 2)  ///
||, xline(0, lp(dash) lc(gs8)) label keep(proimmig_comp1Z trade_pol_china2Z protax_comp1Z proMedicare_comp1Z protrade_comp1Z proChoice_comp1Z guncontrol_comp1Z) ///
order(proimmig_comp1Z protax_comp1Z proMedicare_comp1Z trade_pol_china2Z protrade_comp1Z proChoice_comp1Z guncontrol_comp1Z) ///
xline(-0.1(0.02)0.02, lwidth(thin) lcolor(gs8%30))  xlabel(-0.1(0.02)0.02, angle(horizontal)) xti("Effect on Pr(vote GOP)") ///
mcolor(maroon) msize(large) ciopts(color(maroon) lwidth(0.7)) 

*****************************************************************************
*****************************************************************************

